package com.fourth_groups.shopping121store.ui.person.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.fourth_groups.shopping121store.R;
import com.fourth_groups.shopping121store.bean.Person_verticle;

import java.util.List;

/**
 * Created by Administrator on 2016/10/13.
 */

public class Listadapter extends BaseAdapter{
    private LayoutInflater mInflater;
    private List<Person_verticle> mdata;
    private Context mContext;
    public Listadapter(Context context){
        this.mContext=context;
        mInflater=LayoutInflater.from(context);

    }
    public void setData(List<Person_verticle>list){
        this.mdata=list;
        Log.i("t",list.toString());
        notifyDataSetChanged();

    }
    @Override
    public int getCount() {
        return mdata!=null?mdata.size():0;
    }

    @Override
    public Object getItem(int position) {
        return mdata!=null?mdata.get(position):0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView=mInflater.inflate(R.layout.list_item,parent,false);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
          holder= (ViewHolder) convertView.getTag();
        }
       Person_verticle verticle=mdata.get(position);
            holder.lv_text.setText(verticle.getTitle());
            Glide.with(parent.getContext()).load(verticle.getIcon()).centerCrop().into(holder.lv_img);


        return convertView;
    }
    class ViewHolder{
        ImageView lv_img;
        TextView lv_text;
        public ViewHolder(View convertView){
            lv_img= (ImageView) convertView.findViewById(R.id.lv_img);
            lv_text = (TextView) convertView.findViewById(R.id.lv_text);
        }
    }
}
